/*-------------------------------------------------------------------------*/
/**
  @file		definitions.h
  @author	Renaud Wanschoor
  @date	july 2004
  @version	$Revision: 2.13 $
  @brief	macros of plib  
  
*/
/*--------------------------------------------------------------------------*/

#ifndef DEFINITIONS_H
#define DEFINITIONS_H
/***********************************************
 ***********************************************
 **                                           **
 **                utils.h                    **
 **                                           **
 ***********************************************
 ***********************************************/
#ifdef INFINITY
#undef INFINITY
#endif
#define INFINITY 999999999
#define ABS(a)((a)<0?-(a):(a))

#define LEND (void **) 	0 /**< last argument for functions with a variable number of arguments like U_Free() */

#ifndef METIS
#ifndef PARTY
typedef int idxtype;
#define MAXIDX  (1<<(8*sizeof(idxtype)-2))
#endif
#endif

#define TOOL_PAGRID 	1
#define TOOL_METIS 	2
#define TOOL_PARTY	3
#define TOOL_JOSTLE	4
#define TOOL_PLOT	5

#ifdef PAGRID
#define CALL2VAL(tool,fct,val) val = Pagrid ## _ ## fct /**< Specific tool function interface */
#define CALL(tool,fct) Pagrid ## _ ## fct
/* in metis */
#else
#ifdef METIS
#define CALL2VAL(tool,fct,val) val = Metis ## _ ## fct
#define CALL(tool,fct) Metis ## _ ## fct
/* in party */
#else
#ifdef PARTY
#define CALL2VAL(tool,fct,val) val = Party ## _ ## fct
#define CALL(tool,fct) Party ## _ ## fct
/* in jostle */
#else
#ifdef JOSTLE
#define CALL2VAL(tool,fct,val) val = Jostle ## _ ## fct
#define CALL(tool,fct) Jostle ## _ ## fct
/* in other tool */
#else
#define CALL2VAL(tool,fct,val)		\
{					\
  switch(tool){				\
  case TOOL_PAGRID:			\
    val = Pagrid ## _ ## fct ;		\
    break;				\
  case TOOL_METIS:			\
    val = Metis ## _ ## fct ;		\
    break;				\
  case TOOL_PARTY:			\
    val = Metis ## _ ## fct ;		\
    break;				\
  case TOOL_JOSTLE:			\
    val = Pagrid ## _ ## fct ;		\
    break;				\
  }					\
}
#define CALL(tool,fct)			\
{					\
  switch(tool){				\
  case TOOL_PAGRID:			\
    Pagrid ## _ ## fct ;		\
    break;				\
  case TOOL_METIS:			\
    Metis ## _ ## fct ;	       		\
    break;				\
  case TOOL_PARTY:			\
    Metis ## _ ##fct ;	       		\
    break;				\
  case TOOL_JOSTLE:			\
    Pagrid ## _ ## fct ;	       	\
    break;				\
  }					\
}
#endif
#endif
#endif
#endif

#define U_COL 10 /**< used by pagridplot to read log files, initial number of columns in the structure that stores the log file */
#define U_SIZE 20 /**< used by pagridplot to read log files, initial number of lines in the structure that stores the log file */
char **U_line;
int U_col;
int U_size;

/* macros */
#define MAX(x,y) ((x)>(y)?(x):(y))
#define SQUARE(x) (x)*(x)

/* error handling */
#define ERROR(a) U_error a /**< Fatal error handler (exit the program) ex ERROR((a>b,"fatal error a>b"))*/
#define WARNING(a,b) if(U_Warning a) return (b) /**< Warning error handler (exit current function) ex WARNING((a>b,"warning a>b"),'what the function returns')*/
#define NOTICE(a) U_Warning a /**< Notice error handler (continues) ex NOTICE((a>b,"notice a>b"))*/
#define NOTICE_DO(a,b) if(U_Warning a) b /**< Notice error handler, performs b in case of error ex NOTICE_DO((a>b,"notice a>b, assigning 0 to c"),c=0)*/

/* memory allocation */
#define U_malloc(n,type,msg) (type *)U_smalloc(n,sizeof(type),msg) /**< malloc with error checking */
#define U_mallocset(n,type,ini,msg) (type *)U_ssmalloc ## type (n,ini,msg) /**< malloc with error checking and initialization */
#define U_realloc(ptr,n,type,msg) (type *)U_srealloc(ptr,n,sizeof(type),msg) /**< realloc with error checking */
#define U_mallocxy(x,y,type,msg) (type **)U_smallocxy(x,y,sizeof(type),msg) /**< 2d array dynamic allocation with a single malloc */
#define U_reallocxy(ptr,a,b,c,d,type,msg) (type **)U_sreallocxy(ptr,a,b,c,d,sizeof(type),msg) /**< 2d array realloc when allocated using U_mallocxy */

/* quicksort */
typedef double T;	/* type of item to be sorted */
typedef int tblIndex;	/* type of subscript */
/***********************************************
 ***********************************************
 **                                           **
 **                md_io.h                    **
 **                                           **
 ***********************************************
 ***********************************************/
/* use default when parsing 
 * if not value not assigned by options would be set to 0 */
#define IO_DEFAULT NULL

/* meaning of index for passing default options and default option values*/
#define IO_DEF		12

#define IO_DMATCH 	0
#define IO_DWEIGHT	1
#define IO_DSER 	2
#define IO_DRAND 	3
#define IO_DOUT 	4
#define IO_DBGLVL 	5
#define IO_DPRE         6
#define IO_DIM		7
#define IO_DTOL		8
#define IO_DFLOW	9
#define IO_DBAL		10
#define IO_DUNCO	11

/* default random seed */
#define IO_SEED			4321
/* serialize file name */
#define IO_FSER			"bin"

/* meaning of out in IoCtrl */
#define IO_RESULT 		0
#define IO_ID			1
#define IO_SER			2

/* Matching Schemes */
#define IO_MATCH_RM		1
#define IO_MATCH_HEM		2
#define IO_MATCH_SHEM		4
#define IO_MATCH_SHEMKWAY	8
#define IO_MATCH_SHEBM_ONENORM	16
#define IO_MATCH_SHEBM_INFNORM	32
#define IO_MATCH_SBHEM_ONENORM	64
#define IO_MATCH_SBHEM_INFNORM	128
#define IO_MATCH_MWM		256
#define IO_MATCH_LAM		512

/* Edge Weight for matching */
#define IO_WEIGHT_NORM		1
#define IO_WEIGHT_UPGMA		2

/* serialize options */
#define IO_SER_NONE		1
#define IO_SER_DO		2
#define IO_SER_USE		4

/* random seed options */
#define IO_RAND_NONE		1
#define IO_RAND_INI		2
#define IO_RAND_REFINE		4
#define IO_RAND_ALL		8

/* result output options */
#define IO_OUT_NO		1
#define IO_OUT_NOLEVEL		2
#define IO_OUT_LEVEL		4

/* uncoarsening */
#define IO_UNCO_GREEDY		1
#define IO_UNCO_KL		2
#define IO_UNCO_KLEXEC		4

/* refinement preference */
#define IO_PRE_FULL		1
#define IO_PRE_BOUND		2
#define	IO_PRE_BOUND1		4

#endif

/***********************************************
 ***********************************************
 **                                           **
 **                pqueue.h                   **
 **                                           **
 ***********************************************
 ***********************************************/

#define HEAP_ARRAY	0	/* not really a heap it is a sorted array */
#define HEAP_PAIRING	1	/* pairing heap */
#define HEAP_DLL	2	/* double linked list */

/***********************************************
 ***********************************************
 **                                           **
 **                mem.h                      **
 **                                           **
 ***********************************************
 ***********************************************/
#define MEM_Need(mem,n,type) __MEM_Need(mem,(n)*sizeof(type)) /**< ackncowledge mem structure that it will need to allocade a given amount of space */
#define MEM_Request(mem,n,type) __MEM_Request(mem,(n)*sizeof(type)) /**< request a pointer to a space in memory of a given size */
#define MEM_Needxy(mem,x,y,type) __MEM_Needxy(mem,x,y,sizeof(type)) /**< MEM_Need for 2 dimensional arrays */
#define MEM_Requestxy(mem,x,y,type) __MEM_Requestxy(mem,x,y,sizeof(type)) /**< Mem_Request for 2 dimensional arrays */


/***********************************************
 ***********************************************
 **                                           **
 **                  plib                     **
 **                                           **
 ***********************************************
 ***********************************************/
#define PLIB_STR 256
